/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controlepgto.beans;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author Thiago
 */
@Entity
@Table(name = "compra", catalog = "controlepgto", schema = "")
@NamedQueries({
    @NamedQuery(name = "Compra.findAll", query = "SELECT c FROM Compra c"),
    @NamedQuery(name = "Compra.findByIdCompra", query = "SELECT c FROM Compra c WHERE c.idCompra = :idCompra"),
    @NamedQuery(name = "Compra.findByValorCompra", query = "SELECT c FROM Compra c WHERE c.valorCompra = :valorCompra"),
    @NamedQuery(name = "Compra.findByEntradaCompra", query = "SELECT c FROM Compra c WHERE c.entradaCompra = :entradaCompra"),
    @NamedQuery(name = "Compra.findByDataCompra", query = "SELECT c FROM Compra c WHERE c.dataCompra = :dataCompra"),
    @NamedQuery(name = "Compra.findByQtdeParccompra", query = "SELECT c FROM Compra c WHERE c.qtdeParccompra = :qtdeParccompra"),
    @NamedQuery(name = "Compra.findByTotalItensCompra", query = "SELECT c FROM Compra c WHERE c.totalItensCompra = :totalItensCompra"),
    @NamedQuery(name = "Compra.findByStatusCompra", query = "SELECT c FROM Compra c WHERE c.statusCompra = :statusCompra"),
    @NamedQuery(name = "Compra.findByObsCompra", query = "SELECT c FROM Compra c WHERE c.obsCompra = :obsCompra"),
    @NamedQuery(name = "Compra.findByIdCliente", query = "SELECT c FROM Compra c WHERE c.idCliente = :idCliente")})
public class Compra implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_compra")
    private Integer idCompra;
    @Basic(optional = false)
    @Column(name = "valor_compra")
    private double valorCompra;    
    @Column(name = "entrada_compra")
    private Double entradaCompra;
    @Basic(optional = false)
    @Column(name = "data_compra")
    @Temporal(TemporalType.DATE)
    private Date dataCompra;
    @Basic(optional = false)
    @Column(name = "qtde_Parc_compra")
    private String qtdeParccompra;
    @Column(name = "total_itens_compra")
    private Integer totalItensCompra;
    @Column(name = "status_compra")
    private String statusCompra;
    @Column(name = "obs_compra")
    private String obsCompra;
    @Basic(optional = false)
    
    @JoinColumn(name = "id_compra", referencedColumnName = "id_compra")
    @ManyToOne
     private Cliente  idCliente;   
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idCompra")
    private List<Parcela> parcelaList;

    public Compra() {
    }

    public Compra(Integer idCompra) {
        this.idCompra = idCompra;
    }

    public Compra(Integer idCompra, double valorCompra, Date dataCompra, String qtdeParccompra, Cliente idCliente) {
        this.idCompra = idCompra;
        this.valorCompra = valorCompra;
        this.dataCompra = dataCompra;
        this.qtdeParccompra = qtdeParccompra;
        this.idCliente = idCliente;
    }

    public Integer getIdCompra() {
        return idCompra;
    }

    public void setIdCompra(Integer idCompra) {
        Integer oldIdCompra = this.idCompra;
        this.idCompra = idCompra;
        changeSupport.firePropertyChange("idCompra", oldIdCompra, idCompra);
    }

    public double getValorCompra() {
        return valorCompra;
    }

    public void setValorCompra(double valorCompra) {
        double oldValorCompra = this.valorCompra;
        this.valorCompra = valorCompra;
        changeSupport.firePropertyChange("valorCompra", oldValorCompra, valorCompra);
    }

    public Double getEntradaCompra() {
        return entradaCompra;
    }

    public void setEntradaCompra(Double entradaCompra) {
        Double oldEntradaCompra = this.entradaCompra;
        this.entradaCompra = entradaCompra;
        changeSupport.firePropertyChange("entradaCompra", oldEntradaCompra, entradaCompra);
    }

    public Date getDataCompra() {
        return dataCompra;
    }

    public void setDataCompra(Date dataCompra) {
        Date oldDataCompra = this.dataCompra;
        this.dataCompra = dataCompra;
        changeSupport.firePropertyChange("dataCompra", oldDataCompra, dataCompra);
    }

    public String getQtdeParccompra() {
        return qtdeParccompra;
    }

    public void setQtdeParccompra(String qtdeParccompra) {
        String oldQtdeParccompra = this.qtdeParccompra;
        this.qtdeParccompra = qtdeParccompra;
        changeSupport.firePropertyChange("qtdeParccompra", oldQtdeParccompra, qtdeParccompra);
    }

    public Integer getTotalItensCompra() {
        return totalItensCompra;
    }

    public void setTotalItensCompra(Integer totalItensCompra) {
        Integer oldTotalItensCompra = this.totalItensCompra;
        this.totalItensCompra = totalItensCompra;
        changeSupport.firePropertyChange("totalItensCompra", oldTotalItensCompra, totalItensCompra);
    }

    public String getStatusCompra() {
        return statusCompra;
    }

    public void setStatusCompra(String statusCompra) {
        String oldStatusCompra = this.statusCompra;
        this.statusCompra = statusCompra;
        changeSupport.firePropertyChange("statusCompra", oldStatusCompra, statusCompra);
    }

    public String getObsCompra() {
        return obsCompra;
    }

    public void setObsCompra(String obsCompra) {
        String oldObsCompra = this.obsCompra;
        this.obsCompra = obsCompra;
        changeSupport.firePropertyChange("obsCompra", oldObsCompra, obsCompra);
    }

    public Cliente getIdCliente() {
        return idCliente;
    }

    public void setIdCliente(Cliente idCliente) {
        Cliente oldIdCliente = this.idCliente;
        this.idCliente = idCliente;
        changeSupport.firePropertyChange("idCliente", oldIdCliente, idCliente);
    }

    public List<Parcela> getParcelaList() {
        return parcelaList;
    }

    public void setParcelaList(List<Parcela> parcelaList) {
        this.parcelaList = parcelaList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCompra != null ? idCompra.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Compra)) {
            return false;
        }
        Compra other = (Compra) object;
        if ((this.idCompra == null && other.idCompra != null) || (this.idCompra != null && !this.idCompra.equals(other.idCompra))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "controlepgto.view.Compra[ idCompra=" + idCompra + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
